package com.freewater.javabase.demo.network.netaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class AddressTest {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress inetAddress = InetAddress.getLocalHost();
        System.out.println(getVersion(inetAddress));
    }

    public static int getVersion(InetAddress inetAddress) {
        final byte[] address = inetAddress.getAddress();
        if (address.length == 4) {
            return 4;
        } else if (address.length == 16) {
            return 6;
        } else {
            return -1;
        }
    }
}
